package com.yxjx.duoxue.datamodel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.yxjx.duoxue.utils.UIHelper;

public class DMComment implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3822914039554236479L;
	private String typeName; // 课程或者学校的名字
    private Integer id;
    private String contactName;
    private String contactPhone;
    private Integer commentType;
    private Integer typeId;
    private String commentText;
    private String images;
    private long createTime;

    private DMCommentLevel level = new DMCommentLevel();

    // 目前预留成数组形式
    private ArrayList<DMCommentReply> replys = new ArrayList<DMCommentReply>(0);

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

    public Integer getCommentType() {
        return commentType;
    }

    public void setCommentType(Integer commentType) {
        this.commentType = commentType;
    }

    public Integer getTypeId() {
        return typeId;
    }

    public void setTypeId(Integer typeId) {
        this.typeId = typeId;
    }

    public String getCommentText() {
        return commentText;
    }

    public void setCommentText(String commentText) {
        this.commentText = commentText;
    }

    public String getImages() {
        return images;
    }

    public void setImages(String images) {
        this.images = images;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public ArrayList<DMCommentReply> getReplys() {
        return replys;
    }

    public void setReplys(ArrayList<DMCommentReply> replys) {
        this.replys = replys;
    }

    public DMCommentLevel getLevel() {
        return level;
    }

    public void setLevel(DMCommentLevel level) {
        this.level = level;
    }

    @Override
    public String toString() {
        return "{\"id\":\"" + id + "\", \"contactName\":\"" + contactName + "\", \"contactPhone\":\"" + contactPhone + "\", \"commentType\":\"" + commentType
                + "\", \"typeId\":\"" + typeId + "\", \"commentText\":\"" + commentText + "\", \"images\":\"" + images + "\", \"createTime\":\"" + createTime + "\"}";
    }
    
    /**
     * Parse a DMComment from jsonString
     * didn't include replys and commentLevels.
     * @param str
     * @return
     */
    public static DMComment from(String str) {
    	if (UIHelper.isEmpty(str)) {
    		return null;
    	}
    	DMComment comment = null;
    	try {
    		comment = new DMComment();
			JSONObject jo = new JSONObject(str);
			comment.setCommentText(jo.getString("commentText"));
			comment.setCommentType(jo.getInt("commentType"));
			comment.setContactName(jo.getString("contactName"));
			comment.setContactPhone(jo.getString("contactPhone"));
			comment.setCreateTime(jo.getLong("createTime"));
			comment.setId(jo.getInt("id"));
			comment.setImages(jo.getString("images"));
			comment.setTypeId(jo.getInt("typeId"));
			comment.setTypeName(jo.getString("typeName"));
		} catch (JSONException e) {
			e.printStackTrace();
			
		}
    	return comment;
    }

	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

}